# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: damir <damir@archlinux.org>
# Contributor: Lukas Sabota <punkrockguy318@comcast.net>
# Contributor: Brice Carpentier <brice@dlfp.org>

_name=SCons
pkgname=scons
pkgver=4.6.0
pkgrel=1
pkgdesc="Extensible Python-based build utility"
arch=(any)
url="https://scons.org"
license=(MIT)
depends=(
  python
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-psutil
  python-pytest
)
optdepends=(
  'python-psutil: to wait for processes to exit'
)
source=(
  https://github.com/$pkgname/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz
  https://downloads.sourceforge.net/project/scons/scons/$pkgver/$_name-$pkgver.tar.gz
  $pkgname-4.4.0-dont_install_manpages.patch
)
sha512sums=('d7dd30bbc94ec014b12b37a106aa536dd5c8b16e9f1605b68cad6721cf6e3959add1f75a42693fd8499734ca19eb76f648800d7cc8081fe334282841cd406954'
            'c7dc952117c23ac30b8cf1f70ef0c4ad1c0a86c9865fd255fde1a29ea2fbf9e26573b73430f6adc8c545dab753077f380d29d77ac4eede7fce959c86576d2354'
            '97fb0e54274753b8c94a184a8b811371d314a371abb933b0380b2f990962c341d4d896050501c6889f0568b6d45867dc854ce16d23e9a8540cf4957df7af15a1')
b2sums=('9aeda2ef899dcaf5bc7ca3bc77c0615544f2308f56ef095ad835d5cc748355b467a905ec737eef61a4afd183ff0f041dc244bdd58858ba3abc4f3a4efd9f8dc7'
        'adef2ad5394404ae48d85e8c2a91b5af29e4f9bfa7455504ac1cb8d22d9a05c9ace823e02c8e7a32b34dee281635987487ad43ca94c6adea8e287b086a0732f0'
        'b7b611138f0c672d29f9f56a46802289fed7daac25b12822e60c3d8e076aae3b1b88f144e7b9b1fea3a5092ca80f75ed02480250de65e664e18ec9b8ab5f120e')

prepare() {
  # don't try to install the (non-existent) man pages
  # we'll use them from prebuilt sources, because building them drags in a lot of dependencies, is very brittle and painful
  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-4.4.0-dont_install_manpages.patch
}

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $pkgname-$pkgver
  python runtest.py --all --unit-only
}

package() {
  # install man pages from prebuilt sources
  install -vDm 644 $_name-$pkgver/*.1 -t "$pkgdir/usr/share/man/man1/"

  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {{CHANGES,RELEASE}.txt,README.rst} -t "$pkgdir/usr/share/doc/$pkgname/"

  # remove docbook dirs
  find "$pkgdir" -name 'docbook' -type d -exec rm -frv {} +
}
